var dataTableConfig = {
		"processing" : true,
		"serverSide" : true,
		"paging" : true,
		"lengthChange" : false,
		"searching" : false,
		"ordering" : false,
		"info" : true,
		"autoWidth" : false,
		"oLanguage" : {
			"sProcessing" : "正在加载中......",
			"sLengthMenu" : "每页显示 _MENU_ 条记录",
			"sZeroRecords" : "对不起，查询不到相关数据！",
			"sEmptyTable" : "表中无数据存在！",
			"sInfo" : "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
			"sSearch" : "搜索",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上一页",
				"sNext" : "下一页",
				"sLast" : "末页"
			}
		},
		"oTableTools" : {
			"sRowSelect" : "multi",
			"aButtons" : [
					{
						"sExtends" : "new_record",
						"sButtonText" : "Add"
					},
					{
						"sExtends" : "select",
						"sButtonText" : "Delete Recods",
						"fnClick" : function(nButton,
								oConfig, oFlash) {
							//delete stuff comes here 
							alert('test');
						}

					} ]
		},
		ajax : "/kpiTask/queryKpiTask",
		columns : [
				{
					data : "task_id",
					render : function(data, type, full) {
						return '<input name=\"items\" type="checkbox" id=\"check_'+data+'\" value="' + data + '"/>';
					}
				}, {
					"data" : "task_id"
				},{
					"data" : "obj_name"
				}, {
					"data" : "obj_type_name"
				}, {
					"data" : "kpi_name"
				}, {
					"data" : "method_name"
				},{
					"data": "is_use_name",
				},{
					"data": "period",
				},{
					"data":"componet_bean_class",
				},{
					"data":"oid",
				},{
					"data":"agent_name",
				},{
					"data":"task_name",
				},{
					"data":"access_name",
				},{
					"data":"obj_id",
				},{
					"data":"obj_type",
				},{
					"data":"kpi_id",
				},{
					"data":"method",
				},{
					"data":"is_use",
				},{
					"data":"componet",
				},{
					"data":"agent_id",
				},{
					"data":"group_name",
				},{
					"data":"isConcurrent",
				},{
					"data":"access_id",
				},{
					"data":"rule_script",
				}],
		columnDefs: [    
		        {    
		        	"targets": [13,14,15,16,17,18,19,20,21,22,23], //隐藏第二列，从第0列开始   
		        	"visible": false    
		        }], 
		"dom" : "<'row'<'col-xs-2'l><'#mytool.col-xs-4'><'col-xs-6'f>r>"
				+ "t"
				+ "<'row'<'col-xs-6'i><'col-xs-6'p>>",
};

//初始化表格
var table = $('#kpi_table').DataTable(dataTableConfig);

//全选
$(function() {
	//全选
	$("#checkall_kpi").click(function() {
		$('[name=items]:checkbox').prop("checked", this.checked);
	});
	$('[name=items]:checkbox').click(
		function() {
			var $tmp = $('[name=items]:checkbox');
			$('#checkall_kpi').prop('checked',
					$tmp.length == $tmp.filter(':checked').length);
		}	
	);
});

var app = angular.module('perfKpiApp', []);
var keepDataFlag = false;		//判断关闭模态框时，是否刷新模态框的内容
var fromToUpdateModel = false;  //判断是否来自更新模态框

var initController = app.controller("perfKpiController" , function($scope, $http){
	$('#addModal_perf_kpi').on('hide.bs.modal', function () {
		if(!keepDataFlag){
			document.getElementById("addForm_kpi").reset();
		}
		 
	});
	$('#kpi_select_model').on('hide.bs.modal', function () {
		if(fromToUpdateModel){
			fromToUpdateModel = false;
			$('#updateModal_perf_kpi').modal("toggle");
		}else{
			keepDataFlag = false;
			$('#addModal_perf_kpi').modal("toggle");
		}
		
	});
	$http({
		url : '/deviceManager/getDeviceTypeList',
		method : 'GET'
	}).success(function(data, header, config, status) {
		// 响应成功
		$scope.deviceTypeList = data;
	}).error(function(data, header, config, status) {
		// 处理响应失败
	});
	$http({
		url : '/deviceManager/getDeviceList',
		method : 'GET'
	}).success(function(data, header, config, status) {
		// 响应成功
		$scope.deviceList = data;
	}).error(function(data, header, config, status) {
		// 处理响应失败
	});
	$http({
		url : '/kpiTask/getKpiDefineList',
		method : 'GET'
	}).success(function(data, header, config, status) {
		// 响应成功
		$scope.kpiDefineList = data;
	}).error(function(data, header, config, status) {
		// 处理响应失败
	});
	$http({
		url : '/kpiTask/getComponetList',
		method : 'GET'
	}).success(function(data, header, config, status) {
		// 响应成功
		$scope.componetList = data;
	}).error(function(data, header, config, status) {
		// 处理响应失败
	});
	$http({
		url : '/kpiTask/getAgentList',
		method : 'GET'
	}).success(function(data, header, config, status) {
		// 响应成功
		$scope.agentList = data;
	}).error(function(data, header, config, status) {
		// 处理响应失败
	});
	$scope.add = function(){
		var form = document.getElementById("addForm_kpi");
		var obj_id = form.obj_id_kpi.value;
		var obj_type = form.obj_type_kpi.value;
		var kpi_id = form.kpi_id_kpi.value;
		var method = form.method_kpi.value;
		var rule_script = form.rule_script_kpi.value;
		var is_use = form.is_use_kpi.value;
		var period = form.period_kpi.value;
		var componet = form.componet_kpi.value;
		var oid = form.oid_kpi.value;
		var agent_id = form.agent_id_kpi.value;
		var task_name = form.task_name_kpi.value;
		var group_name = form.group_name_kpi.value;
		var isConcurrent = form.isConcurrent_kpi.value;
		var accessId = form.access_kpi.value;
		$http({
			url : '/kpiTask/add',
			params:{obj_id:obj_id, obj_type:obj_type, kpi_id:kpi_id , method:method, rule_script:rule_script, is_use:is_use,
				period:period, componet:componet, oid:oid, agent_id:agent_id, task_name:task_name, group_name:group_name,
				isConcurrent:isConcurrent, accessId:accessId},
			method : 'GET'
		}).success(function(data, header, config, status) {
			// 响应成功
			if(data=="1"){
				$('#addSuccessAlert_kpi').fadeIn(2000);
				$('#addSuccessAlert_kpi').fadeOut(2000);
				table.draw();
			}else{
				$('#addFailedAlert_kpi').fadeIn(2000);
				$('#addFailedAlert_kpi').fadeOut(2000);
			}
		}).error(function(data, header, config, status) {
			// 处理响应失败
			$('#addFailedAlert_kpi').fadeIn(2000);
			$('#addFailedAlert_kpi').fadeOut(2000);
		});
	};
	$scope.del_init=function(){
		var taskIds = "";
		$('[name=items]:checkbox:checked').each(function() {
			taskIds += $(this).val() + ";";
		});
		if(taskIds==""){
			$('#selAlert_kpi').html("<strong>请选择记录进行删除！</strong>");
			$('#alertModal_kpi').modal("toggle");
		}else{
			$("#delModal_kpi").modal("toggle");
		}
		
	};
	$scope.del = function(){
		var taskIds = "";
		$('[name=items]:checkbox:checked').each(function() {
			taskIds += $(this).val() + ";";
		});
		if(taskIds==""){
			alert("请选择要删除的记录！");
		}else{
			$http({
				url : '/kpiTask/delete',
				params:{taskIds:taskIds},
				method : 'GET'
			}).success(function(data, header, config, status) {
				// 响应成功
				if(data==true){
					$('#promptContent_kpi').hide();
					$('#del_kpi').hide();
					$('#deleteSuccessAlert_kpi').fadeIn(2000);
					$('#delModal_kpi').on('hide.bs.modal', function () {
						table.draw();
						$('#del_kpi').show();
						$('#deleteSuccessAlert_kpi').hide();
						$('#promptContent_kpi').show();
					});
				}else{
					$('#promptContent_kpi').hide();
					$('#del_kpi').hide();
					$('#deleteFailedAlert_kpi').fadeIn(2000);
					$('#delModal_kpi').on('hide.bs.modal', function () {
						table.draw();
						$('#del_kpi').show();
						$('#deleteFailedAlert_kpi').hide();
						$('#promptContent_kpi').show();
					});
				}
				
			}).error(function(data, header, config, status) {
				// 处理响应失败
				$('#promptContent_kpi').hide();
				$('#del_kpi').hide();
				$('#deleteFailedAlert_kpi').fadeIn(2000);
				$('#delModal_kpi').on('hide.bs.modal', function () {
					$('#del_kpi').show();
					$('#deleteFailedAlert_kpi').hide();
					$('#promptContent_kpi').show();
				});
			});
		}
	};
	$scope.update_init =function(){
		var taskIds = "";
		document.getElementById("updateForm_kpi").reset();
		$('[name=items]:checkbox:checked').each(function() {
			taskIds += $(this).val() + ";";
		});
		if(taskIds==""){
			$('#selAlert_kpi').html("<strong>请选择要修改的记录！</strong>");
			$('#alertModal_kpi').modal("toggle");
		}else if(taskIds.split(";").length>2){
			$('#selAlert_kpi').html("<strong>修改的记录数不能大于1.</strong>");
			$('#alertModal_kpi').modal("toggle");
		}else{
			  
			 $('[name=items]:checkbox').each(function(key,value){
		            if($(value).prop('checked')){
		            	var selRow =$('#kpi_table').dataTable().fnGetData(key-1);
		            	$scope.id_update = selRow.task_id;
		            	$scope.obj_id_update = selRow.obj_id;
		            	$scope.obj_name_update = selRow.obj_name;
		            	$scope.obj_type_id_update = selRow.obj_type;
		            	$scope.obj_type_name_update = selRow.obj_type_name;
		            	$scope.kpi_id_update = selRow.kpi_id;
		            	$scope.kpi_name_update = selRow.kpi_name;
		            	$scope.method_update = selRow.method;
		            	$scope.method_name_update = selRow.method_name;
		            	$scope.rule_script_update = selRow.rule_script;
		            	$scope.is_use_update = selRow.is_use;
		            	$scope.period_update = selRow.period;
		            	$scope.componet_update = selRow.componet;
		            	$scope.componet_name_update = selRow.componet_bean_class;
		            	$scope.oid_update = selRow.oid;
		            	$scope.agent_id_update = selRow.agent_id;
		            	$scope.agent_name_update = selRow.agent_name;
		            	$scope.task_name_update = selRow.task_name;
		            	$scope.group_name_update = selRow.group_name;
		            	$scope.isConcurrent_update = selRow.isConcurrent;
		            	$scope.access_update = selRow.access_id;
		            }
			 });
			 $("#updateModal_perf_kpi").modal("toggle");
		}
	};
	$scope.update = function(){
		var form = document.getElementById("updateForm_kpi");
		var task_id = form.id_update_kpi.value;
		var obj_id = form.obj_id_update_kpi.value;
		var obj_type = form.obj_type_update_kpi.value;
		var kpi_id = form.kpi_id_update_kpi.value;
		var method = form.method_update_kpi.value;
		var rule_script = form.rule_script_update_kpi.value;
		var is_use = form.is_use_update_kpi.value;
		var period = form.period_update_kpi.value;
		var componet = form.componet_update_kpi.value;
		var oid = form.oid_update_kpi.value;
		var agent_id = form.agent_id_update_kpi.value;
		var task_name = form.task_name_update_kpi.value;
		var group_name = form.group_name_update_kpi.value;
		var isConcurrent = form.isConcurrent_update_kpi.value;
		var accessId = form.access_update_kpi.value;
		$http({
			url : '/kpiTask/edit',
			params:{obj_id:obj_id, obj_type:obj_type, kpi_id:kpi_id , method:method, rule_script:rule_script, is_use:is_use,
				period:period, componet:componet, oid:oid, agent_id:agent_id, task_name:task_name, group_name:group_name,
				isConcurrent:isConcurrent,task_id:task_id,accessId:accessId},
			method : 'GET'
		}).success(function(data, header, config, status) {
			// 响应成功
			if(data=="1"){
				$('#updateSuccessAlert_kpi').fadeIn(2000);
				$('#updateSuccessAlert_kpi').fadeOut(2000);
				table.draw();
			}else{
				$('#updateFailedAlert_kpi').fadeIn(2000);
				$('#updateFailedAlert_kpi').fadeOut(2000);
			}
		}).error(function(data, header, config, status){
			// 处理响应失败
			$('#updateFailedAlert_kpi').fadeIn(2000);
			$('#updateFailedAlert_kpi').fadeOut(2000);
		});
	}
	
	$scope.query = function () {
		var url = '/kpiTask/queryKpiTask';
		var data = {};
		var form =document.getElementById("queryForm_kpi");  // $('#queryForm');
		if(form.obj_type_query_kpi.value!=0){
			data.obj_type =  form.obj_type_query_kpi.value;
		}
		if(form.obj_name_query_kpi.value!=0){
			data.obj_name = form.obj_name_query_kpi.value;
		}
		if(form.kpi_name_query_kpi.value!=0){
			data.kpi_name =  form.kpi_name_query_kpi.value;
		}
		if(form.task_name_query_kpi.value!=0){
			data.task_name =  form.task_name_query_kpi.value;
		}
		if(form.is_use_query_kpi.value){
			data.is_use =  form.is_use_query_kpi.value;
		}
		if(form.method_query_kpi.value!=0){
			data.method =  form.method_query_kpi.value;
		}
		$('#queryBtn_kpi').attr("disabled", "true");
		
		$('#kpi_table').dataTable().api().destroy();
		dataTableConfig.ajax={"url": url, "data":data};
		dataTableConfig.fnDrawCallback = function(settings){
			$('#queryBtn_kpi').removeAttr("disabled");
		};
		table=$('#kpi_table').dataTable(dataTableConfig);
	};
	
	//kpi选择模态框相关的function
	$scope.kpi_query = function () {
		var url = '/kpiDefine/queryKpiDefine';
		var data = {};
		var form =document.getElementById("queryForm_kpi_define");  // $('#queryForm');
		if(form.code_query_kpi_define.value!=0){
			data.code =  form.code_query_kpi_define.value;
		}
		if(form.name_query_kpi_define.value!=0){
			data.name = form.name_query_kpi_define.value;
		}
		if(form.type_id_query_kpi_define.value!=0){
			data.type_id=  form.type_id_query_kpi_define.value;
		}
		if(form.is_use_query_kpi_define.value!=0){
			data.is_use =  form.is_use_query_kpi_define.value;
		}
		if(form.obj_type_query_kpi_define.value!=0){
			data.obj_type =  form.obj_type_query_kpi_define.value;
		}
		$('#queryBtn_kpi_define').attr("disabled", "true");
		$('#kpi_define_table').dataTable().api().destroy();
		kpiDefineDataTableConfig.ajax={"url": url, "data":data};
		kpiDefineDataTableConfig.fnDrawCallback = function(settings){
			$('#queryBtn_kpi_define').removeAttr("disabled");
		};
		kpi_define_table=$('#kpi_define_table').dataTable(kpiDefineDataTableConfig);
	};
	$scope.sel_kpi_model = function(){
		keepDataFlag = true;
		$('#kpi_define_table').dataTable().api().destroy();
		kpi_define_table = $('#kpi_define_table').DataTable(kpiDefineDataTableConfig);
		$("#addModal_perf_kpi").modal("hide");
		$("#kpi_select_model").modal("toggle");
	};
	$scope.sel_kpi_commit = function(){
		var selKpiIds = "";
		$('[name=items_kpi]:checkbox:checked').each(function() {
			selKpiIds += $(this).val() + ";";
		});
		if(selKpiIds==""){
			$('#selKpiAlert_kpi').html("<strong>请选择KPI记录！</strong>");
			$('#selKpiAlert_kpi').fadeIn(2000);
			$('#selKpiAlert_kpi').fadeOut(2000);
		}else if(selKpiIds.split(";").length>2){
			$('#selKpiAlert_kpi').html("<strong>选择的KPI记录数不能大于1.</strong>");
			$('#selKpiAlert_kpi').fadeIn(2000);
			$('#selKpiAlert_kpi').fadeOut(2000);
		}else{
			$("[name=items_kpi]:checkbox").each(function(key,value){
	            if($(value).prop('checked')){
	            	var selRow =$('#kpi_define_table').dataTable().fnGetData(key);
	    			var selKpiId = selRow.kpi_id;
	    			if(fromToUpdateModel){
	    				$('#kpi_id_update_kpi').val(selKpiId);
	    			}else{
	    				$('#kpi_id_kpi').val(selKpiId);
	    			}
	    			
	            }
			});
			$("#kpi_select_model").modal("toggle");
		}
	};
	$scope.sel_kpi_update_model = function(){
		keepDataFlag = true;
		fromToUpdateModel = true;
		$('#kpi_define_table').dataTable().api().destroy();
		kpi_define_table = $('#kpi_define_table').DataTable(kpiDefineDataTableConfig);
		$("#updateModal_perf_kpi").modal("hide");
		$("#kpi_select_model").modal("toggle");
	};
	
	
	//Component模态框相关function
	$('#component_select_model').on('hide.bs.modal', function () {
		if(fromToUpdateModel){
			fromToUpdateModel = false;
			$('#updateModal_perf_kpi').modal("toggle");
		}else{
			keepDataFlag = false;
			$('#addModal_perf_kpi').modal("toggle");
		}
		
	});
	
	$scope.component_query = function () {
		var url = '/component/queryComponent';
		var data = {};
		var form =document.getElementById("queryForm_component");  // $('#queryForm');
		if(form.bean_class_query_component.value!=0){
			data.bean_class =  form.bean_class_query_component.value;
		}
		$('#queryBtn_component').attr("disabled", "true");
		
		$('#component_table').dataTable().api().destroy();
		componentDataTableConfig.ajax={"url": url, "data":data};
		componentDataTableConfig.fnDrawCallback = function(settings){
			$('#queryBtn_component').removeAttr("disabled");
		};
		component_table=$('#component_table').dataTable(componentDataTableConfig);
	};
	$scope.sel_component_model = function(){
		keepDataFlag = true;
		$('#component_table').dataTable().api().destroy();
		component_table = $('#component_table').DataTable(componentDataTableConfig);
		$("#addModal_perf_kpi").modal("toggle");
		$("#component_select_model").modal("toggle");
	};
	$scope.sel_component_commit = function(){
		var selComponentIds = "";
		$('[name=items_component]:checkbox:checked').each(function() {
			selComponentIds += $(this).val() + ";";
		});
		if(selComponentIds==""){
			$('#selComponentAlert_kpi').html("<strong>请选择组件记录！</strong>");
			$('#selComponentAlert_kpi').fadeIn(2000);
			$('#selComponentAlert_kpi').fadeOut(2000);
		}else if(selComponentIds.split(";").length>2){
			$('#selComponentAlert_kpi').html("<strong>选择的Component记录数不能大于1.</strong>");
			$('#selComponentAlert_kpi').fadeIn(2000);
			$('#selComponentAlert_kpi').fadeOut(2000);
		}else{
			$("[name=items_component]:checkbox").each(function(key,value){
	            if($(value).prop('checked')){
	            	var selRow =$('#component_table').dataTable().fnGetData(key);
	    			var selComponentId = selRow.id;
	    			if(fromToUpdateModel){
	    				$('#componet_update_kpi').val(selComponentId);
	    			}else{
	    				$('#componet_kpi').val(selComponentId);
	    			}
	            }
			});
			$("#component_select_model").modal("toggle");
		}
	};
	$scope.sel_component_update_model = function(){
		keepDataFlag = true;
		fromToUpdateModel = true;
		$('#component_table').dataTable().api().destroy();
		component_table = $('#component_table').DataTable(componentDataTableConfig);
		$("#updateModal_perf_kpi").modal("toggle");
		$("#component_select_model").modal("toggle");
	};
	
	
	//接入点模态框相关function
	$('#access_select_model').on('hide.bs.modal', function () {
		if(fromToUpdateModel){
			fromToUpdateModel = false;
			$('#updateModal_perf_kpi').modal("toggle");
		}else{
			keepDataFlag = false;
			$('#addModal_perf_kpi').modal("toggle");
		}
		
	});
	
	$scope.access_query = function () {
		var url = '/access/queryAccess';
		var data = {};
		var form =document.getElementById("queryForm_access");  // $('#queryForm');
		if(form.type_code_query_access.value!=0){
			data.type_code =  form.type_code_query_access.value;
		}
		$('#queryBtn_access').attr("disabled", "true");
		$('#access_table').dataTable().api().destroy();
		accessDataTableConfig.ajax={"url": url, "data":data};
		accessDataTableConfig.fnDrawCallback = function(settings){
			$('#queryBtn_access').removeAttr("disabled");
		};
		access_table=$('#access_table').dataTable(accessDataTableConfig);
	};
	$scope.sel_access_model = function(){
		keepDataFlag = true;
		$('#access_table').dataTable().api().destroy();
		access_table = $('#access_table').DataTable(accessDataTableConfig);
		$("#addModal_perf_kpi").modal("toggle");
		$("#access_select_model").modal("toggle");
	};
	$scope.sel_access_commit = function(){
		var selAccessIds = "";
		$('[name=items_access]:checkbox:checked').each(function() {
			selAccessIds += $(this).val() + ";";
		});
		if(selAccessIds==""){
			if(fromToUpdateModel){
				$('#access_update_kpi').val("");
			}else{
				$('#access_kpi').val("");
			}
			$("#access_select_model").modal("toggle");
		}else if(selAccessIds.split(";").length>2){
			$('#selAccessAlert_kpi').html("<strong>选择的Access记录数不能大于1.</strong>");
			$('#selAccessAlert_kpi').fadeIn(2000);
			$('#selAccessAlert_kpi').fadeOut(2000);
		}else{
			$("[name=items_access]:checkbox").each(function(key,value){
	            if($(value).prop('checked')){
	            	var selRow =$('#access_table').dataTable().fnGetData(key);
	    			var selAccessId = selRow.id;
	    			if(fromToUpdateModel){
	    				$('#access_update_kpi').val(selAccessId);
	    			}else{
	    				$('#access_kpi').val(selAccessId);
	    			}
	            }
			});
			$("#access_select_model").modal("toggle");
		}
	};
	$scope.sel_access_update_model = function(){
		keepDataFlag = true;
		fromToUpdateModel = true;
		$('#access_table').dataTable().api().destroy();
		access_table = $('#access_table').DataTable(accessDataTableConfig);
		$("#updateModal_perf_kpi").modal("hide");
		$("#access_select_model").modal("toggle");
	};
	
	
	//代理采集机模态框相关function
	$('#agent_select_model').on('hide.bs.modal', function () {
		if(fromToUpdateModel){
			fromToUpdateModel = false;
			$('#updateModal_perf_kpi').modal("toggle");
		}else{
			keepDataFlag = false;
			$('#addModal_perf_kpi').modal("toggle");
		}
		
	});
	
	$scope.agent_query = function () {
		var url = '/agent/queryAgent';
		var data = {};
		var form =document.getElementById("queryForm_agent");  // $('#queryForm');
		if(form.code_query_agent.value!=0){
			data.code =  form.code_query_agent.value;
		}
		if(form.name_query_agent.value!=0){
			data.name = form.name_query_agent.value;
		}
		$('#queryBtn_agent').attr("disabled", "true");
		
		$('#agent_table').dataTable().api().destroy();
		agentDataTableConfig.ajax={"url": url, "data":data};
		agentDataTableConfig.fnDrawCallback = function(settings){
			$('#queryBtn_agent').removeAttr("disabled");
		};
		agent_table=$('#agent_table').dataTable(agentDataTableConfig);
	};
	$scope.sel_agent_model = function(){
		keepDataFlag = true;
		$('#agent_table').dataTable().api().destroy();
		access_table = $('#agent_table').DataTable(agentDataTableConfig);
		$("#addModal_perf_kpi").modal("toggle");
		$("#agent_select_model").modal("toggle");
	};
	$scope.sel_agent_commit = function(){
		var selAgentIds = "";
		$('[name=items_agent]:checkbox:checked').each(function() {
			selAgentIds += $(this).val() + ";";
		});
		if(selAgentIds==""){
			if(fromToUpdateModel){
				$('#agent_id_update_kpi').val("");
			}else{
				$('#agent_id_kpi').val("");
			}
			$("#agent_select_model").modal("toggle");
		}else if(selAgentIds.split(";").length>2){
			$('#selAgentAlert_kpi').html("<strong>选择的Access记录数不能大于1.</strong>");
			$('#selAgentAlert_kpi').fadeIn(2000);
			$('#selAgentAlert_kpi').fadeOut(2000);
		}else{
			$("[name=items_agent]:checkbox").each(function(key,value){
	            if($(value).prop('checked')){
	            	var selRow =$('#agent_table').dataTable().fnGetData(key);
	    			var selAgentId = selRow.agent_id;
	    			if(fromToUpdateModel){
	    				$('#agent_id_update_kpi').val(selAgentId);
	    			}else{
	    				$('#agent_id_kpi').val(selAgentId);
	    			}
	            }
			});
			$("#agent_select_model").modal("toggle");
		}
	};
	$scope.sel_agent_update_model = function(){
		keepDataFlag = true;
		fromToUpdateModel = true;
		$('#agent_table').dataTable().api().destroy();
		agent_table = $('#agent_table').DataTable(agentDataTableConfig);
		$("#updateModal_perf_kpi").modal("hide");
		$("#agent_select_model").modal("toggle");
	};
		
});
var kpiDefineDataTableConfig = {
		"processing" : true,
		"serverSide" : true,
		"paging" : true,
		"lengthChange" : false,
		"searching" : false,
		"ordering" : false,
		"info" : true,
		"autoWidth" : false,
		"oLanguage" : {
			"sProcessing" : "正在加载中......",
			"sLengthMenu" : "每页显示 _MENU_ 条记录",
			"sZeroRecords" : "对不起，查询不到相关数据！",
			"sEmptyTable" : "表中无数据存在！",
			"sInfo" : "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
			"sSearch" : "搜索",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上一页",
				"sNext" : "下一页",
				"sLast" : "末页"
			}
		},
		"oTableTools" : {
			"sRowSelect" : "multi",
			"aButtons" : [
					{
						"sExtends" : "new_record",
						"sButtonText" : "Add"
					},
					{
						"sExtends" : "select",
						"sButtonText" : "Delete Recods",
						"fnClick" : function(nButton,
								oConfig, oFlash) {
							//delete stuff comes here 
							alert('test');
						}

					} ]
		},
		ajax : "/kpiDefine/queryKpiDefine",
		columns : [
				{
					data : "kpi_id",
					render : function(data, type, full) {
						return '<input name=\"items_kpi\" type="checkbox" id=\"check_'+data+'\" value="' + data + '"/>';
					}
				}, {
					"data" : "kpi_id"
				},{
					"data" : "code"
				}, {
					"data" : "kpi_name"
				}, {
					"data" : "device_type_name"
				}, {
					"data" : "device_name"
				},{
					"data": "is_use_comment",
				},{
					"data": "value_type",
				},{
					"data": "obj_type_comment",
				},{
					"data": "device_type_id",
				},{
					"data": "obj_id",
				},{
					"data": "is_use",
				},{
					"data": "obj_type",
				},{
					"data": "bit"
				}],
		columnDefs: [    
		        {    
		        	"targets": [9,10,11,12,13],    
		        	"visible": false    
		        }], 
		"dom" : "<'row'<'col-xs-2'l><'#mytool.col-xs-4'><'col-xs-6'f>r>"
				+ "t"
				+ "<'row'<'col-xs-6'i><'col-xs-6'p>>",
};
//初始化表格
var kpi_define_table = $('#kpi_define_table').DataTable(kpiDefineDataTableConfig);

//组件选择模态框table加载配置
var componentDataTableConfig = {
		"processing" : true,
		"serverSide" : true,
		"paging" : true,
		"lengthChange" : false,
		"searching" : false,
		"ordering" : false,
		"info" : true,
		"autoWidth" : false,
		"oLanguage" : {
			"sProcessing" : "正在加载中......",
			"sLengthMenu" : "每页显示 _MENU_ 条记录",
			"sZeroRecords" : "对不起，查询不到相关数据！",
			"sEmptyTable" : "表中无数据存在！",
			"sInfo" : "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
			"sSearch" : "搜索",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上一页",
				"sNext" : "下一页",
				"sLast" : "末页"
			}
		},
		"oTableTools" : {
			"sRowSelect" : "multi",
			"aButtons" : [
					{
						"sExtends" : "new_record",
						"sButtonText" : "Add"
					},
					{
						"sExtends" : "select",
						"sButtonText" : "Delete Recods",
						"fnClick" : function(nButton,
								oConfig, oFlash) {
							//delete stuff comes here 
							alert('test');
						}

					} ]
		},
		ajax : "/component/queryComponent",
		columns : [
				{
					data : "id",
					render : function(data, type, full) {
						return '<input name=\"items_component\" type="checkbox" id=\"check_'+data+'\" value="' + data + '"/>';
					}
				}, {
					"data" : "id"
				},{
					"data" : "bean_class"
				}, {
					"data" : "bean_class_path"
				}, {
					"data" : "state_name"
				}, {
					"data" : "comment"
				}, {
					"data" : "url_path"
				}, {
					"data" : "state"
				}, {
					"data" : "create_date"
				}],
		columnDefs: [{    
		             	"targets": [7,8], 
						"visible": false    
		             }], 
		"dom" : "<'row'<'col-xs-2'l><'#mytool.col-xs-4'><'col-xs-6'f>r>"
				+ "t"
				+ "<'row'<'col-xs-6'i><'col-xs-6'p>>",
};

//初始化表格
var component_table = $('#component_table').DataTable(componentDataTableConfig);


//接入点模态框表格
var accessDataTableConfig = {
		"processing" : true,
		"serverSide" : true,
		"paging" : true,
		"lengthChange" : false,
		"searching" : false,
		"ordering" : false,
		"info" : true,
		"autoWidth" : false,
		"oLanguage" : {
			"sProcessing" : "正在加载中......",
			"sLengthMenu" : "每页显示 _MENU_ 条记录",
			"sZeroRecords" : "对不起，查询不到相关数据！",
			"sEmptyTable" : "表中无数据存在！",
			"sInfo" : "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
			"sSearch" : "搜索",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上一页",
				"sNext" : "下一页",
				"sLast" : "末页"
			}
		},
		"oTableTools" : {
			"sRowSelect" : "multi",
			"aButtons" : [
					{
						"sExtends" : "new_record",
						"sButtonText" : "Add"
					},
					{
						"sExtends" : "select",
						"sButtonText" : "Delete Recods",
						"fnClick" : function(nButton,
								oConfig, oFlash) {
							//delete stuff comes here 
							alert('test');
						}

					} ]
		},
		ajax : "/access/queryAccess",
		columns : [
				{
					data : "id",
					render : function(data, type, full) {
						return '<input name=\"items_access\" type="checkbox" id=\"check_'+data+'\" value="' + data + '"/>';
					}
				}, {
					"data" : "id"
				},{
					"data" : "type_code"
				}, {
					"data" : "ip"
				}, {
					"data" : "port"
				}, {
					"data" : "snmp_commity"
				}, {
					"data" : "url"
				}, {
					"data" : "state_name"
				}, {
					"data" : "create_date"
				}, {
					"data" : "modify_date"
				}, {
					"data" : "sign"
				}, {
					"data" : "state"
				}, {
					"data" : "username"
				}, {
					"data" : "password"
				}],
		columnDefs: [{    
		             	"targets": [8,9,10,11,12,13], 
						"visible": false    
		             }], 
		"dom" : "<'row'<'col-xs-2'l><'#mytool.col-xs-4'><'col-xs-6'f>r>"
				+ "t"
				+ "<'row'<'col-xs-6'i><'col-xs-6'p>>",
};
//初始化表格
var access_table = $('#access_table').DataTable(componentDataTableConfig);




//代理采集机模态框表
var agentDataTableConfig = {
		"processing" : true,
		"serverSide" : true,
		"paging" : true,
		"lengthChange" : false,
		"searching" : false,
		"ordering" : false,
		"info" : true,
		"autoWidth" : false,
		"oLanguage" : {
			"sProcessing" : "正在加载中......",
			"sLengthMenu" : "每页显示 _MENU_ 条记录",
			"sZeroRecords" : "对不起，查询不到相关数据！",
			"sEmptyTable" : "表中无数据存在！",
			"sInfo" : "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
			"sSearch" : "搜索",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上一页",
				"sNext" : "下一页",
				"sLast" : "末页"
			}
		},
		"oTableTools" : {
			"sRowSelect" : "multi",
			"aButtons" : [
					{
						"sExtends" : "new_record",
						"sButtonText" : "Add"
					},
					{
						"sExtends" : "select",
						"sButtonText" : "Delete Recods",
						"fnClick" : function(nButton,
								oConfig, oFlash) {
							//delete stuff comes here 
							alert('test');
						}

					} ]
		},
		ajax : "/agent/queryAgent",
		columns : [
				{
					data : "agent_id",
					render : function(data, type, full) {
						return '<input name=\"items_agent\" type="checkbox" id=\"check_'+data+'\" value="' + data + '"/>';
					}
				}, {
					"data" : "agent_id"
				},{
					"data" : "code"
				}, {
					"data" : "name"
				}, {
					"data" : "ip"
				}, {
					"data" : "port"
				}],
		"dom" : "<'row'<'col-xs-2'l><'#mytool.col-xs-4'><'col-xs-6'f>r>"
				+ "t"
				+ "<'row'<'col-xs-6'i><'col-xs-6'p>>",
};

//初始化表格
var agent_table = $('#agent_table').DataTable(agentDataTableConfig);